package com.sfx.utils;

import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created with IntelliJ IDEA.
 * Description: 拷贝Bean
 * User: sfx
 * Date: 2023-07-10
 * Time: 14:03
 */
public class BeanCopyUtils {
    public BeanCopyUtils() {

    }

    /**
     * 拷贝对象
     * @param bean
     * @param clazz
     * @return
     * @param <V>
     */
    public static <V> V copyBean(Object bean,Class<V> clazz) {
        return BeanUtil.copyProperties(bean, clazz);
    }

    /**
     * 拷贝集合
     * @param list
     * @param clazz
     * @return
     * @param <V>
     */
    public static <O,V> List<V> copyBeanList(List<O> list, Class<V> clazz) {
        return list.stream().map(o -> copyBean(o, clazz)).collect(Collectors.toList());
    }
}